package ${controllerPackage};
#parse("/template/func.vm")#set ($className =  $table.className)
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import ${comonPath}.common.components.DataGrid;
import ${comonPath}.common.components.DataGridJson;
import ${comonPath}.common.utilself.JSONUtil;

import ${entityPackage}.${className};
import ${servicePackage}.${className}Service;
import ${page};

/**
* @className:${className}Controller
* @description: $!table.remark
* @version:v1.0.0 
* @author:$author
* @date:$now
* @Copyright $copyright
*/

@Controller
public class ${className}Controller  {

	private static final Logger logger = LoggerFactory.getLogger(${className}Controller.class);
	@Autowired
	private ${className}Service #uncap_first(${className})Service;

	
	/**
	 *  @description:到列表页面
	 *  $author
	 */
	@RequestMapping(value = "${adminPath}/#uncap_first(${className})/list", method = RequestMethod.GET)
	public String tolist(HttpServletRequest request, HttpServletResponse response) {
		return "modules/#uncap_first(${className})/#uncap_first(${className})List";
	}

	
    /**
     *  @description:到新增保存页面
     *  $author
     */
    @RequestMapping(value = "${adminPath}/#uncap_first(${className})/create", method = RequestMethod.GET)
    public String toCreate(HttpServletRequest request, HttpServletResponse response) {
        return "modules/#uncap_first(${className})/#uncap_first(${className})Create";
    }

    /**
     *  @description:修改页面
     *  $author
     */
    @RequestMapping(value = "${adminPath}/#uncap_first(${className})/edit")
    public String toEdit(HttpServletRequest request, HttpServletResponse response) {
        return "modules/#uncap_first(${className})/#uncap_first(${className})Edit";
    }

    /**
     *  @description:返回json数据
     *  $author
     */
    @RequestMapping(value = "${adminPath}/#uncap_first(${className})/list/json", produces = {"application/json;charset=UTF-8"} )
    @ResponseBody
    public String list(HttpServletRequest request, HttpServletResponse response,${className} #uncap_first(${className}) ) {
        Page<?> page = #uncap_first(${className})Service.selectByPage(#uncap_first(${className}), new Page<Object>(request,response) );
        return page.toJson();
    }

	/**
	 *  @description:保存
	 *  $author
	 */
	@RequestMapping(value = "${adminPath}/#uncap_first(${className})/save")
    @ResponseBody
	public Map<String, String> save(${className} #uncap_first(${className}) ) {
        Map<String, String> map = new HashMap<String,String>();
        #uncap_first(${className})Service.save(#uncap_first(${className}) );
        map.put("success","true");
        map.put("message","保存成功");
		return map;
	}
	
	
	/**
	 *  @description:修改
	 *  $author
	 */
	@RequestMapping(value = "${adminPath}/#uncap_first(${className})/update")
    @ResponseBody
	public Map<String, String> update(${className} #uncap_first(${className}) ) {
        Map<String, String> map = new HashMap<String,String>();
        #uncap_first(${className})Service.updateSelectiveByPrimaryKey(#uncap_first(${className}) );
        map.put("success","true");
        map.put("message","保存成功");
		return map;
	}
	
	/**
	 *  @description:删除 $author
	 *  如果没物理删除就不要启动这段代码，一般的删除也是更新标示
	 */
//	@RequestMapping(value = "${adminPath}/#uncap_first(${className})/delete")
//    @ResponseBody
//	public Map delete(#ID_TYPE_NAME) {
//        Map<String, String> map = new HashMap<String,String>();
//        #uncap_first(${className})Service.deleteByPrimaryKey( #ID_NAME );
//        map.put("success","true");
//        map.put("message","保存成功");
//        return map;
//	}
	
    /**
     *  @description:返回json数据
     *  $author
     */
    @RequestMapping(value = "${adminPath}/#uncap_first(${className})/list/getQueryJson", produces = {"application/json;charset=UTF-8"} )
    @ResponseBody
    public String getQueryJson( HttpServletRequest request, 
					    		HttpServletResponse response,
					    		${className} #uncap_first(${className}),
					    		Page<?> page,
					    		DataGrid dg,
					    		ModelMap mMap) {
        
    	DataGridJson json = #uncap_first(${className})Service.selectByPageJson(request,#uncap_first(${className}), page, dg, mMap);
		return JSONUtil.toJson(json);
    }
 
    


}
